<?php
/**
 * Created by PhpStorm.
 * User: Ellon_Wong
 * Date: 14-5-10
 * Time: 下午3:56
 */

include_once dirname(__FILE__) . '/../../lib/pdfcrowd-2.7-php/pdfcrowd.php';

function GenerateResume_func($arg_body){
try
{
    global $pdf_Crowd_username;
    global $pdf_Crowd_apikey;
    global $picUrl;
    if(!array_key_exists("user_Id",$arg_body)){
        return MsgArray(false,"用户id参数错误",[],"Warn");
    }
    if(!array_key_exists("r_name",$arg_body)){
        return MsgArray(false,"姓名参数错误",[],"Warn");
    }
    if(!array_key_exists("r_sex",$arg_body)){
        return MsgArray(false,"性别参数错误",[],"Warn");
    }
    if(!array_key_exists("r_birth",$arg_body)){
        return MsgArray(false,"出生年月参数错误",[],"Warn");
    }
    if(!array_key_exists("r_connect",$arg_body)){
        return MsgArray(false,"联系方式参数错误",[],"Warn");
    }
    if(!array_key_exists("r_position",$arg_body)){
        return MsgArray(false,"意向职位参数错误",[],"Warn");
    }
    if(!array_key_exists("r_exsalary",$arg_body)){
        return MsgArray(false,"预期薪资参数错误",[],"Warn");
    }
    if(!array_key_exists("r_workPlace",$arg_body)){
        return MsgArray(false,"工作地点参数错误",[],"Warn");
    }
    if(!array_key_exists("r_edu",$arg_body)){
        return MsgArray(false,"教育经历参数错误",[],"Warn");
    }
    if(!array_key_exists("r_hobby",$arg_body)){
        return MsgArray(false,"兴趣爱好参数错误",[],"Warn");
    }
    if(!array_key_exists("r_launage",$arg_body)){
        return MsgArray(false,"语言能力参数错误",[],"Warn");
    }
    if(!array_key_exists("r_personalIn",$arg_body)){
        return MsgArray(false,"自我评价参数错误",[],"Warn");
    }
    if(!array_key_exists("r_work",$arg_body)){
        return MsgArray(false,"工作经历参数错误",[],"Warn");
    }
    if(!array_key_exists("r_skill",$arg_body)){
        return MsgArray(false,"相关技能参数错误",[],"Warn");
    }

    $userName=$arg_body["user_Id"];
    $path = "generateResume/ResumeFolder/".$userName.".pdf";
    // create an API client instance
    $client = new Pdfcrowd($pdf_Crowd_username, $pdf_Crowd_apikey);

    // convert a web page and store the generated PDF into a $pdf variable
    $out_file = fopen($path, "wb");

    $html = "<head>
    <title>个人简历</title>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head><body>
        <table style='width: 100%'>

                <td style='width: 80%'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <tr>
                            <td><h1>".$arg_body["r_name"]."</h1></td>
                        <tr>
                            <td style='font-weight: bold'>性别：".$arg_body["r_sex"]."</td>
                            <td style='font-weight: bold'>出生年月：".$arg_body["r_birth"]."</td>
                        </tr>
                        <tr>
                            <td style='font-weight: bold'>联系方式：".$arg_body["r_connect"]."</td>
                        </tr>

                    </table>
                </td>
                <td  style='width: 20%;vertical-align: top'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <tr>
                              <img style='position:fixed; padding:0; border:0;width:278px;height: 150px;' src ='".$picUrl.$arg_body["user_Id"].".jpg'>
                        <tr>

                        </tr>

                    </table>
                </td>

<tr>
                <td  colspan='1'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='2'>
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>教育经历</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'><pre>".$arg_body["r_edu"]."</pre></td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>
    <td  colspan='1'>
        <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
            <td colspan='1' >
                <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>求职意向</h3>
            </td>
            <tr>
                <td style='font-weight: bold'>意向职位：".$arg_body["r_position"]."</td>

            </tr>
            <tr>
                <td style='font-weight: bold'>期望薪资：".$arg_body["r_exsalary"]."</td>
            </tr>
            <tr>
                <td style='font-weight: bold'>工作地点：".$arg_body["r_workPlace"]."</td>
            </tr>

        </table>
    </td>
</tr>
            <tr>
                <td  colspan='1'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='2' >
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>工作/实习经历</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'><pre>".$arg_body["r_work"]."</pre></td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>
                <td  colspan='1'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='1' >
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>语言能力</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'><pre>".$arg_body["r_launage"]."</pre></td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>
            </tr>

            <tr>
                <td  colspan='1'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='2' >
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>相关技能</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'>".$arg_body["r_skill"]."</td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>
                <td  colspan='1'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='1' >
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>兴趣爱好</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'>".$arg_body["r_hobby"]."</td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>
            </tr>
            <tr>
                <td  colspan='2'>
                    <table style='width: 100%;box-shadow: 1px 1px 4px #e8e8e8;border: 1px solid #DCF0F1;border-radius: 5px;background: #FFF;color: #666;height: 150px;'>
                        <td colspan='2' >
                            <h3 style='background: #DCF0F1;color: teal;width: 99%;margin-left:0.5%'>自我评价</h3>
                        </td>
                        <tr>
                            <td style='font-weight: bold'>".$arg_body["r_personalIn"]."</td>

                        </tr>
                        <tr>
                            <td style='font-weight: bold'></td>
                        </tr>

                    </table>
                </td>

            </tr>
        </table>
        </body>";
    $pdf = $client->convertHtml($html,$out_file);


    // set HTTP response headers
    header("Content-Type: application/pdf");
    header("Cache-Control: max-age=0");
    header("Accept-Ranges: none");
    header("Content-Disposition: attachment; filename=\"google_com.pdf\"");
    fclose($out_file);
    // send the generated PDF

    $clientPath = "womenService/src/".$path;

    return  MsgArray(true,"生成pdf成功",$clientPath,"Success");

}
catch(PdfcrowdException $why)
{
    return MsgArray(false,"生成pdf失败","","Error");
}
}
